package start.doubudouyin.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import start.doubudouyin.entity.Systemmessage;
import start.doubudouyin.service.SystemmessageService;
import start.doubudouyin.service.VideoinfoService;
import start.doubudouyin.utils.Result;

import java.util.List;

@RestController
@RequestMapping("/system")
@CrossOrigin(origins = "http://localhost:5173/")
public class SystemmessageController {
    @Resource
    private SystemmessageService systemmessageService;
    @Resource
    private VideoinfoService videoinfoService;

    @PutMapping("/rejectvideo")
    public Result rejectvideo(@RequestParam("adminId") String adminId, @RequestParam("userId") String userId,
    @RequestParam("content") String content){
         if(systemmessageService.rejectvideo(adminId,userId,content)>0){
             return Result.success();
         }else{
             return Result.error("300","发送通知失败");
         }
    }

    @DeleteMapping("/deletevideo")
    public Result deletevideo(@RequestParam("adminId") String adminId, @RequestParam("userId") String userId,
                              @RequestParam("content") String content,@RequestParam("videoId") String videoId){
        if(videoinfoService.removeById(videoId)&&systemmessageService.rejectvideo(adminId,userId,content)>0){
            return Result.success();
        }else{
            return Result.error("300","删除视频失败");
        }
    }

    @GetMapping("/getsystemmessage")
    public Result getsystemmessage(@RequestParam("userId") String userId){
        List<Systemmessage> list = systemmessageService.getsystemmessage(userId);
        return Result.success(list);
    }
}
